<template>
  <div>
    <div v-if="!isDatil">
      <div class="condition">
        <span>
          年份：
          <el-date-picker
            v-model="year"
            type="year"
            value-format="yyyy"
            :clearable="false"
            placeholder="选择年"
            @change="changeYear"
            size="small"
          />
        </span>
      </div>
      <div class="manHours">合计工时数：{{sumWorkingHours}}</div>
      <base-table
        ref="baseTable"
        :tableSetting="tableSetting"
        @getdata="getdata"
        @handleCommon="handleCommon"
      ></base-table>
    </div>
    <personYear v-else :userId="userId" />
  </div>
</template>

<script>
import baseTable from "@/components/table/baseTable";
import personYear from "./personYear";
import { yearReportList, userAnnWorkHours } from "@/service/Api.js"; //接口
export default {
  components: { baseTable, personYear },
  name: "weekly",
  data() {
    return {
      tableSetting: {
        defaulteParams: {
          year: "",
        },
        init: 100,
        tableApiFn: yearReportList,
        options: [
          { prop: "number", label: "排名" },
          { prop: "name", label: "姓名" },
          { prop: "sumTime", label: "年度总工时" },
        ],
        btns: [
          {
            text: "查看",
            size: "mini",
            handleName: "lookDatil",
            type: "success",
          },
        ],
      },
      year: "",
      sumWorkingHours: "",
      isDatil: false,
      userId: "",
    };
  },
  created() {
    let date = new Date();
    this.year = date.getFullYear() +"";
    this.tableSetting.defaulteParams.year = date.getFullYear();
  },
  methods: {
    handleCommon(name, row, idx) {
      if (this[name]) {
        this[name](row, idx);
      }
    },
    getdata(val) {
      this.sumWorkingHours = val.sumWorkingHours.toFixed(2);
    },
    changeYear() {
      this.tableSetting.defaulteParams.year = this.year;
      this.$refs.baseTable.initData();
    },
    //查看
    lookDatil(row) {
      console.log(row);
      this.userId = row.uid;
      this.isDatil = true;
    },
  },
};
</script>

<style scoped>
.condition {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.manHours {
  text-align: center;
  border: 1px solid #ebeef5;
  border-bottom: 0;
  padding: 10px 0;
  color: #707070;
  font-weight: bold;
  background: #f9f9f9;
  margin-top: 10px;
}
</style>
